/***************************************************************************
 *   Copyright (C) 2006 by Yuri Ovcharenko                                 *
 *   amwsoft@gmail.com                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef DC_H
#define DC_H

#include <QMainWindow>
#include <QValidator>
#include <QDir>

/**
 * @author Yuri Ovcharenko <amwsoft@gmail.com>
 */

class QCloseEvent;
class QSettings;
class QLabel;
class QStatusBar;
class QComboBox;
class QTabWidget;
class QFrame;
class QMenu;
class QAction;
class Serial;
class Console;
class SerialSettings;
class ConsoleSettings;
class PluginManager;

class HexValidator : public QValidator
{
    Q_OBJECT
  public:
    HexValidator(QObject *parent = 0);
    ~HexValidator();
  virtual QValidator::State validate (QString & input, int & pos) const;
};

class DC : public QMainWindow
{
    Q_OBJECT
  public:
    DC( QWidget *parent = 0 );
    ~DC();

  public:
    void closeEvent(QCloseEvent *e);

  private:
    void saveSettings();

  private slots:
    void slotAbout();
    void slotAboutQt();
    void slotConsoleChar(const QChar & c);
    void slotReceive(const QByteArray & d);
    void slotPortOpened();
    void slotSerialSettings();
    void slotConsoleSettings();
    void slotTransmit(const QString & d);

    void slotActivatePlugin();
    void slotActivatePlugin(const QString & pname);
    void slotDeactivatePlugin();
    void slotConfigurePlugins();

    void slotAtPluginStart(bool needClose);
    void slotPluginStopped(bool canOpen);

    void slotTabChanged(int index);

  private:
    QDir appPrefix;
    QSettings *settings;
    QLabel *msgConsole;
    QLabel *msgSerial;
    QStatusBar *stBar;
    Serial *serial;
    Console *console;
    bool hexConsole;
    QComboBox *cbTransmit;
    SerialSettings *serialSettings;
    QTabWidget *tabs;
    QFrame *consoleFrame;
    ConsoleSettings *consoleSettings;
    QString port;
    int baud;

    QMenu *pluginsMenu;
    QAction *actClosePlugin;
    PluginManager *pluginManager;
};

#endif
